package com.cheng.example.atguigu.view2.client38;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;


/**
 * 阻塞队列api之返回布尔组
 * 不会抛出异常
 */
public class BlockingQueueDemo {

    public static void main(String[] args) throws InterruptedException {
        f2();
    }


    /**
     * 阻塞队列api之返回布尔组
     * offer提供
     * peek看一眼
     * poll获得
     */
    public static void f2(){
        BlockingQueue blockingQueue = new ArrayBlockingQueue(3);
        System.out.println(blockingQueue.offer("a"));
        System.out.println(blockingQueue.offer("b"));
        System.out.println(blockingQueue.offer("c"));

        try {
            System.out.println(blockingQueue.offer("d", 2,TimeUnit.SECONDS));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(blockingQueue.peek());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.peek());
    }


}
